package com.hsq.ndmall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.hsq.ndmall.common.utils.PageUtils;
import com.hsq.ndmall.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import com.hsq.ndmall.product.entity.CategoryEntity;
import com.hsq.ndmall.product.service.CategoryService;
import io.swagger.annotations.Api;


/**
 * 类目表
 *
 * @author kate-chan
 * @email ccsu_loader@163.com
 * @date 2021-08-11 00:33:11
 */
@Api(tags = "CategoryController", description = "类目表服务")
@RestController
@RequestMapping("product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:category:list")
    @ApiOperation("获取所有类目表信息")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = categoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("product:category:info")
    @ApiOperation("获取指定id的类目表详情")
    public R info(@PathVariable("id") Integer id) {
        CategoryEntity category = categoryService.getById(id);

        return R.ok().put("category", category);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加类目表信息")
    //@RequiresPermissions("product:category:save")
    public R save(@RequestBody CategoryEntity category) {
        categoryService.save(category);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id类目表信息")
    //@RequiresPermissions("product:category:update")
    public R update(@RequestBody CategoryEntity category) {
        categoryService.updateById(category);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id类目表信息")
    //@RequiresPermissions("product:category:delete")
    public R delete(@RequestBody Integer[] ids) {
        categoryService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }


    @GetMapping("test")
    public R MyTest() {
        return categoryService.findTopCategory();
    }

    /*
       获取分类楼层商品列表
        */
    @GetMapping("/floor")
    public R floorGoodsList(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit){

        PageUtils pageCat = categoryService.getCategory2GoodsList(page, limit);
        return R.ok().put("page",pageCat);
    }
}
